/**
 * meilele.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package com.gpagers.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * @author liuzijie@meilele.com
 * @version $Id: Menus.java, v 0.1 2016年5月9日 上午10:44:18 liuzijie@meilele.com Exp $
 */
public class Menus {

    public Menus() {
    }

    public Menu init(final Shell shell) {
        //main menu
        Menu main = new Menu(shell, SWT.BAR);
        //first section
        MenuItem file = new MenuItem(main, SWT.CASCADE);
        file.setText("操作");
        //drop down style for file open window
        Menu filemenu = new Menu(shell, SWT.DROP_DOWN);
        //new file item
        //        MenuItem newItem =  new MenuItem(filemenu, SWT.PUSH);
        //        newItem.setText("新建(&N) ALT+SHIFT+N");
        //        newItem.setAccelerator(SWT.ALT+SWT.SHIFT+'N');
        //open menu item
        //        MenuItem openItem =  new MenuItem(filemenu, SWT.PUSH);
        //        openItem.setText("打开(&O)");
        //        openItem.addListener(SWT.Selection,new Listener() {
        //            @Override
        //            public void handleEvent(Event arg0) {
        //                FileDialog filedlg=new FileDialog(shell,SWT.OPEN);
        //                filedlg.setText("文件选择");
        //                filedlg.setFilterPath("SystemRoot");
        //                //打开文件对话框，返回选中文件的绝对路径
        //               /* try {
        //                    FileSDK.readFileByLines(filedlg.open());
        //                } catch (Exception e) {
        //                    e.printStackTrace();
        //                }*/
        //                
        //            }
        //        });

        //space line item
        //new MenuItem(filemenu, SWT.SEPARATOR);
        //exit item
        MenuItem exitItem = new MenuItem(filemenu, SWT.PUSH);
        exitItem.setText("退出(&E)");
        exitItem.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event arg0) {
                shell.dispose();
            }
        });
        //add filedropdown menu to filemenu
        file.setMenu(filemenu);

        //the second menuitem
        //        MenuItem view = new MenuItem(main, SWT.CASCADE);
        //        view.setText("视图(&V)");
        //        
        //        Menu viewMenu =  new Menu(shell,SWT.DROP_DOWN);
        //        MenuItem normalItem =  new MenuItem(viewMenu,SWT.RADIO);
        //        normalItem.setText("普通(&N)");
        //        view.setMenu(viewMenu);

        return main;
    }
}
